{% extends 'basic_app/master.html' %}
{% block tag_left %}
    {% include 'oratk_app/tag_left_user.html' %}
{% endblock %}
{% block title %}
    <title>ORATK</title>
{% endblock %}
{% block userinfo %}
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        <form name="Form" role="search" action="/oratk_app/oratk_monitor_immediate" onsubmit="return validateForm()"
              method="POST">
            <h3 class="page-header">即时巡检</h3>
            <div class="navbar-form navbar-left">
                &nbsp 选择实例: &nbsp
                {#                <select class="form-control" name="conn_string" id="conn_string">#}
                <select class="selectpicker show-tick " style="width:450px" data-live-search="true" name="conn_string"
                        id="conn_string">

                    <option id="def">--请选择实例名--</option>
                    {% for i in instanceinfo_result %}
                        <option id="a">{{ i.dbname }}={{ i.conn_string }}</option>
                    {% endfor %}
                </select>
                <button type="submit" class="btn btn-default" id="btSearch">即时巡检</button>
                <div>&nbsp</div>
                {#                <h3 class="page-header">执行结果</h3>#}
                <h3 class="page-header">巡检记录</h3>
            <span  class="btn btn-default" onclick="refresh()">刷新</span>
            <span style="color: red">&nbsp 查看报告后，点击刷新查看最新备注信息</span>
                <div id="tab_detail" table_count={{ table_count }}></div>
            </div>
        </form>
        <table class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
                <th>开始时间</th>
                {#                <th>结束时间</th>#}
                <th>数据库</th>
                <th>连接串</th>
                <th>巡检耗时(s)</th>
                <th>状态</th>
                <th>备注</th>
                <th>操作</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id="tabbody">
            {% for i in current_page %}
                <tr>
                    <td style="display:none">{{ i.batch_id }}</td>
                    <td>{{ i.start_time }}</td>
                    {#                    <td>{{ i.end_time }}</td>#}
                    <td>{{ i.db_name }}</td>
                    <td>{{ i.db_conn }}</td>
                    <td>{{ i.sub_time }}</td>
                    <td>{{ i.status }}</td>
                    <td>{{ i.remark }}</td>
                    <td><a
                            href="/oratk_app/oratk_monitor_immediate_report?batch_id={{ i.batch_id }}&db_name={{ i.db_name }}"
                            target="_blank" onclick="check(this)" err=" ">查看报告</a>
                    </td>
                    <td><a href="/oratk_app/oratk_monitor_immediate_report_info?batch_id={{ i.batch_id }}"
                           target="_blank">查看巡检详情</a></td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
        {#        以上是分页#}
        {% include 'basic_app/paginator.html' %}
    </div>
    </div>

{% endblock %}

{% block script %}
    <script>
        //即时按钮执行前判断输入框是否有空值
        function validateForm() {
            var select_conn = $('#conn_string').find("option:checked").attr("id")
            if (select_conn == 'def') {
                alert('请选择实例')
                return false;
            }
        }
        $(document).ready(function () {
            $('#tabbody tr').each(function (i) {
                var err_list = [];
                $(this).children('td').each(function (j) {
                    //如果状态为error或running ,字体标红
                    if (j == 5) {
                        if ($(this).text() == 'error' || $(this).text() == 'running') {
                            $(this).css('color', 'red')
                            err_list.push('1')
                        }
                        if ($(this).text() == 'success') {
                            $(this).css('color', 'green')
                        }
                    }
                    //如果状态为error或running    1、a标签禁止跳转  2、为自定义属性"err"赋值
                    if (j == 7) {
                        if (err_list.length > 0) {
                            $(this).children('a').attr('href', '#');
                            $(this).children('a').attr('err', 'err');
                            $(this).click(function (event) {
                                event.preventDefault();
                            })


                        }
                    }
                });
            })
        })
       //如果状态为error或running     alter"查询报告不可用"
        function check(which){
            {#location.reload();#}
            var val = $(which).attr("err")
            if (val == 'err'){
                alert("此条目无法查看报告,请查看巡检详情")
            }
        }
        function refresh(){
            location.reload();
        }
    </script>
{% endblock %}
